<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->


<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.Type" content="topic">
<meta name="DC.Title" content="配置Oracle数据库侦听参数">
<meta name="product" content="">
<meta name="DC.Relation" scheme="URI" content="oracle_gud_0119.html">
<meta name="prodname" content="">
<meta name="version" content="">
<meta name="brand" content="">
<meta name="DC.Publisher" content="20250306">
<meta name="prodname" content="csbs">
<meta name="documenttype" content="usermanual">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="oracle_gud_0125">
<meta name="DC.Language" content="zh-cn">
<link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
<title>配置Oracle数据库侦听参数</title>
</head>
<body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px"><a name="oracle_gud_0125"></a><a name="oracle_gud_0125"></a>

<h1 class="topictitle1">配置Oracle数据库侦听参数</h1>
<div><p>如果需要对即时挂载的数据库进行远程访问，请先配置Oracle数据库的侦听参数。</p>
<div class="section"><h4 class="sectiontitle">背景信息</h4><p>即时挂载产生的数据库与副本对应的源数据库侦听IP和端口一致，导致即时挂载的数据库无法远程访问，因此，需要为即时挂载的数据库配置侦听IP和端口。</p>
</div>
<div class="section"><h4 class="sectiontitle">操作步骤</h4><ol><li id="oracle_gud_0125__li6675175142415"><span>登录Oracle数据库主机。</span><p><ul id="oracle_gud_0125__oracle_gud_0020_zh-cn_topic_0000001656760969_ul1983714162204"><li id="oracle_gud_0125__oracle_gud_0020_zh-cn_topic_0000001656760969_li7258697580">如果是Linux操作系统，请使用PuTTY登录Oracle数据库主机，并执行<strong id="oracle_gud_0125__oracle_gud_0020_zh-cn_topic_0000001656760969_b119369483451">su - oracle</strong>命令，切换到<strong id="oracle_gud_0125__oracle_gud_0020_zh-cn_topic_0000001656760969_b2486163014495">oracle</strong>账户。</li><li id="oracle_gud_0125__oracle_gud_0020_zh-cn_topic_0000001656760969_li1366015032013">如果是Windows操作系统，请使用系统管理员登录Oracle数据库主机。</li></ul>
</p></li><li><span>执行以下命令查看数据库侦听程序的状态。</span><p><p><strong>lsnrctl status</strong></p>
<ul><li>当回显类似如下，表示侦听程序处于侦听状态，则继续执行<a href="#oracle_gud_0125__li56151443117">3</a>。<pre class="screen">[oracle@localhost <font style="font-size:8pt" Face="Courier New" >~</font>]$ lsnrctl status
LSNRCTL for Linux: Version 18.0.0.0.0 - Production on 14-MAY-2021 04:33:58
Copyright (c) 1991, 2018, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 18.0.0.0.0 - Production
Start Date                14-MAY-2021 04:33:54
Uptime                    0 days 0 hr. 0 min. 6 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
The listener supports no services
The command completed successfully</pre>
</li><li>如果侦听程序未处于侦听状态，执行<strong>lsnrctl start</strong>命令启动侦听。</li></ul>
</p></li><li id="oracle_gud_0125__li56151443117"><a name="oracle_gud_0125__li56151443117"></a><a name="li56151443117"></a><span>执行以下命令查看侦听端口。</span><p><ul><li>如果是Linux操作系统，请执行以下命令：<p><strong>cat $ORACLE_HOME/network/admin/listener.ora</strong></p>
<ul><li>如果回显提示该目录下没有<span class="uicontrol">“listener.ora”</span>文件，则说明端口默认为1521。</li><li>如果回显类似如下信息，则“PORT”的值为要查询的侦听端口。<pre class="screen">LISTENER =
#  (ADDRESS_LIST=
#       (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(<strong>PORT=1521</strong>))</pre>
</li></ul>
</li><li>如果是Windows操作系统，请执行以下操作：<ol type="a"><li>在键盘上按<span class="uicontrol" id="oracle_gud_0125__oracle_gud_0016_uicontrol11819941114510">“Win+R”</span>，打开运行窗口。</li><li>输入<span class="parmvalue">“regedit”</span>，打开注册表，在“Computer\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDB<em>19Home1</em>”路径下获取“ORACLE_HOME”的路径。<div class="note"><img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span><div class="notebody"><p>路径中“KEY_OraDB<em>19Home1”</em>为示例，请以实际为准。</p>
</div></div>
</li><li>进入“ORACLE_HOME”路径查看是否存在<span class="uicontrol">“listener.ora”</span>文件。<ul><li>如果不存在，则说明端口默认为1521。</li><li>如果存在，则该文件中“PORT”的值为要查询的侦听端口。<div class="p">示例：<pre class="screen">LISTENER =
#  (ADDRESS_LIST=
#       (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(<strong>PORT=1521</strong>))</pre>
</div>
</li></ul>
</li></ol>
</li></ul>
</p></li><li><span>开放侦听端口。</span><p><ul><li>如果是Linux操作系统，请执行以下命令查询防火墙开启状态：<p><strong>systemctl status firewalld</strong></p>
<ul><li>如果回显显示“Active: inactive”，表示未开启防火墙，则跳过本步骤。</li><li>如果回显显示“Active: active”，表示已开启防火墙，则执行以下命令开放侦听端口。<p><strong>su - root</strong></p>
<p><strong>/sbin/iptables -I INPUT -p tcp --dport </strong><em>端口号</em><strong> -j ACCEPT</strong></p>
<p><strong>iptables save</strong></p>
<div class="note"><img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span><div class="notebody"><p>命令中的<em>端口号</em>为<a href="#oracle_gud_0125__li56151443117">3</a>中查询到的侦听端口。</p>
</div></div>
</li></ul>
</li><li>如果是Windows操作系统，请执行以下操作：<ol type="a"><li>打开“控制面板”，单击“系统和安全”。</li><li>选择“Windows Defender 防火墙 &gt; 启用或关闭 Windows Defender 防火墙”。</li><li>将专用网络和公共网络均设置“关闭 Windows Defender 防火墙(不推荐)”。</li><li>单击“确认”。</li></ol>
</li></ul>
</p></li><li><span>修改数据库侦听参数。</span><p><ol type="a"><li>执行以下命令，登录Oracle数据库实例。<ul id="oracle_gud_0125__oracle_gud_0016_ul7420345341"><li id="oracle_gud_0125__oracle_gud_0016_li15682124913711">OS认证：<ul id="oracle_gud_0125__oracle_gud_0016_ul89443983816"><li id="oracle_gud_0125__oracle_gud_0016_li18420124173415">如果是Linux操作系统，请执行以下命令：<p id="oracle_gud_0125__oracle_gud_0016_p95148598366"><a name="oracle_gud_0125__oracle_gud_0016_li18420124173415"></a><a name="oracle_gud_0016_li18420124173415"></a><strong id="oracle_gud_0125__oracle_gud_0016_b14236563719">export ORACLE_SID=</strong><em id="oracle_gud_0125__oracle_gud_0016_i85144598369">数据库实例名称</em></p>
<p id="oracle_gud_0125__oracle_gud_0016_p145141259153613"><strong id="oracle_gud_0125__oracle_gud_0016_b1597618293715">sqlplus / as sysdba</strong></p>
</li><li id="oracle_gud_0125__oracle_gud_0016_li7402151163816">如果是Windows操作系统，请执行以下操作：<ol class="substepthirdol" id="oracle_gud_0125__oracle_gud_0016_ol124110408264"><li id="oracle_gud_0125__oracle_gud_0016_li624120402267">在键盘上按<span class="uicontrol" id="oracle_gud_0125__oracle_gud_0016_oracle_gud_0016_uicontrol11819941114510">“Win+R”</span>，打开运行窗口。</li><li id="oracle_gud_0125__oracle_gud_0016_li161821338277">输入<span class="parmvalue" id="oracle_gud_0125__oracle_gud_0016_parmvalue122291222476">“cmd”</span>，执行以下命令。<p id="oracle_gud_0125__oracle_gud_0016_p1755152313372"><strong id="oracle_gud_0125__oracle_gud_0016_b19591532143713">set ORACLE_SID=</strong><em id="oracle_gud_0125__oracle_gud_0016_i16755423133718">数据库实例名称</em></p>
<p id="oracle_gud_0125__oracle_gud_0016_p1075515234379"><strong id="oracle_gud_0125__oracle_gud_0016_b540852910371">sqlplus / as sysdba</strong></p>
</li></ol>
</li></ul>
</li><li id="oracle_gud_0125__oracle_gud_0016_li105571236103417">数据库认证：<ul id="oracle_gud_0125__oracle_gud_0016_ul1136516538386"><li id="oracle_gud_0125__oracle_gud_0016_li1723334817382">如果是Linux操作系统，请执行以下命令：<p id="oracle_gud_0125__oracle_gud_0016_p920984963717"><a name="oracle_gud_0125__oracle_gud_0016_li1723334817382"></a><a name="oracle_gud_0016_li1723334817382"></a><strong id="oracle_gud_0125__oracle_gud_0016_b19174355163720">export ORACLE_SID=</strong><em id="oracle_gud_0125__oracle_gud_0016_i1420924973715">数据库实例名称</em></p>
<p id="oracle_gud_0125__oracle_gud_0016_p182093496371"><strong id="oracle_gud_0125__oracle_gud_0016_b034785743716">sqlplus</strong></p>
<p id="oracle_gud_0125__oracle_gud_0016_p17915722412">根据提示输入具备<strong id="oracle_gud_0125__oracle_gud_0016_b1691518214115">sysdba</strong>权限的用户：</p>
<pre class="screen" id="oracle_gud_0125__oracle_gud_0016_screen9915112104114"><em id="oracle_gud_0125__oracle_gud_0016_i1915102164113">username </em>as sysdba</pre>
<p id="oracle_gud_0125__oracle_gud_0016_p159150224117">根据提示输入密码。</p>
</li><li id="oracle_gud_0125__oracle_gud_0016_li122822426407">Windows OS执行以下命令：<ol class="substepthirdol" id="oracle_gud_0125__oracle_gud_0016_ol587720252273"><li id="oracle_gud_0125__oracle_gud_0016_li5168124414479">在键盘上按<span class="uicontrol" id="oracle_gud_0125__oracle_gud_0016_oracle_gud_0016_uicontrol11819941114510_1">“Win+R”</span>，打开运行窗口。</li><li id="oracle_gud_0125__oracle_gud_0016_li3877172517270">输入<span class="parmvalue" id="oracle_gud_0125__oracle_gud_0016_parmvalue2059612503475">“cmd”</span>，执行以下命令。<p id="oracle_gud_0125__oracle_gud_0016_p8745723103813"><strong id="oracle_gud_0125__oracle_gud_0016_b9408122923816">set ORACLE_SID=</strong><em id="oracle_gud_0125__oracle_gud_0016_i12745162318389">数据库实例名称</em></p>
<p id="oracle_gud_0125__oracle_gud_0016_p15745182333814"><strong id="oracle_gud_0125__oracle_gud_0016_b11154427163811">sqlplus</strong></p>
<p id="oracle_gud_0125__oracle_gud_0016_p71274192512">根据提示输入具备<strong id="oracle_gud_0125__oracle_gud_0016_b17349199162611">sysdba</strong>权限的用户：</p>
<pre class="screen" id="oracle_gud_0125__oracle_gud_0016_screen18896121620243"><em id="oracle_gud_0125__oracle_gud_0016_i380114413256">username </em>as sysdba</pre>
<p id="oracle_gud_0125__oracle_gud_0016_p15251105852511">根据提示输入密码。</p>
</li></ol>
</li></ul>
</li></ul>
</li><li>执行以下命令修改数据库侦听IP和端口。<p><strong>alter system set local_listener="(address = (protocol = tcp)(host =</strong><em>当前数据库主机IP</em><strong>)(port = </strong><em>查询到的端口</em><strong>))";</strong></p>
</li><li>执行以下命令检查侦听参数是否修改成功。<p><strong>show parameter local_listener;</strong></p>
<div class="p">回显类似如下，host和port为修改后的值，表示修改成功。<pre class="screen">SQL&gt;  show parameter local_listener;

NAME                                 TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
local_listener                       string
(address = (protocol = tcp)(host = 192.168.97.161)(port = 1521))</pre>
</div>
</li></ol>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>父主题：</strong> <a href="oracle_gud_0119.html">常见问题</a></div>
</div>
</div>

<div class="hrcopyright"><hr size="2"></div><div class="hwcopyright">版权所有 &copy; 华为技术有限公司</div></body>
</html>